<?php
class Control {
	protected $view;
	
	/**
	 * 构造方法，将view属性实例化为View类的实例，并设置模块路径
	 */
	public function __construct() {
		$this->view = new View();
		$this->view->caching=true;
		$this->view->setTemplateDir('./View/' . GROUP . '/' . MODULE);
		$this->view->setCompileDir('./Cache/template_c');
		$this->view->setCacheDir('./Cache/cache');
		function smarty_block_nocache ($param,$content,$smarty){
			return $content;
		}
		$this->view->registerPlugin("function","nocache", "smarty_block_nocache");
	}
	
	/**
	 * 操作成功之后的显示界面
	 *
	 * @param string $url
	 *        	跳转的url
	 * @param string $msg
	 *        	输出的信息
	 * @param int $waitSeconds
	 *        	停留秒数
	 */
	public function success($url, $msg = '操作成功', $waitSeconds = 1) {
		header ( 'Refresh:' . $waitSeconds . ';url=' . $url );
		echo "<div style='color:green;font-weight:bold;border:1px solid #336699'>" . $msg . '</div>';
	}
	
	/**
	 * 操作失败之后的显示界面
	 *
	 * @param string $url
	 *        	跳转的url
	 * @param string $msg
	 *        	输出的信息
	 * @param int $waitSeconds
	 *        	停留秒数
	 */
	public function error($url, $msg = '操作失败', $waitSeconds = 2) {
		header ( 'Refresh:' . $waitSeconds . ';url=' . $url );
		echo "<div style='color:red;font-weight:bold;border:1px solid #336699'>" . $msg . '</div>';
	}
	
	/**
	 * 实现普通页面跳转
	 *
	 * @param string $url
	 *        	要跳转的页面地址
	 */
	public function jump($url) {
		header ( 'location:' . $url );
	}
}